var fs = require('fs');
var path = require('path');
var DxfStruct = require('./DxfStruct2');
var DxfParser = require('../');

var DXF_FILE_PATH = path.join(__dirname, 'data', 'sx.dxf');
var OUTPUT_FILE_NAME = "cad.json";

var fileStream = fs.createReadStream(DXF_FILE_PATH, { encoding: 'utf8' });
var parser = new DxfParser();
var layer_color = {}

parser.parseStream(fileStream, function (err, dxf) {
    if (err) return console.error(err.stack);
    //fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxf, null, 3));

    dxf.sys = { start: 2, points: [], dn: 800 }
    dxfstruct = new DxfStruct(dxf)

    var newLayer = {
        layer: [ '交通线层','道路中线层',
                '1_DN225','1_DN63','1_DN0','1_DN110','1_DN160','1_DN90',
                '1_DN25','1_DN32','1_DN50','1_DN80','1_DN100','1_DN150','1_DN200','1_DN300','1_DN400','1_DN500','1_DN600','1_DN800',
               ],
        
        //hatch: ['0'],
        //blocks: false,
        merge: ['交通线层','道路中线层','DN0','DN25','DN32'],
        new: {
            '1_DN225': 'DN200',
            '1_DN63': 'DN50',
            '1_DN0': 'DN0',
            '1_DN110': 'DN100',
            '1_DN160': 'DN150',
            '1_DN90': 'DN80',
            
            '1_DN25': 'DN25',
            '1_DN32': 'DN32',
            '1_DN50': 'DN50',
            '1_DN80': 'DN80',
            '1_DN100': 'DN100',
            '1_DN150': 'DN150',
            '1_DN200': 'DN200',
            '1_DN300': 'DN300',
            '1_DN400': 'DN400',
            '1_DN500': 'DN500',
            '1_DN600': 'DN600',
            '1_DN800': 'DN800',
        },
       
        tlayers: {
            // '名称注记层': { c: '12237498', b: false },
            // '管线标注': { c: '12237498', b: false },
            '交通线层': { c: '12237498', b: false },
            '道路中线层': { c: '11382189', b: false },
            'DN0': { c: '11382189', b: false },
            'DN25': { c: '11382189', b: false },
            'DN32': { c: '11382189', b: false },

            'DN50': { c: '3065801', b: true },
            'DN80': { c: '11969246', b: true },
            'DN100': { c: '5943791', b: true },
            'DN150': { c: '16759168', b: true },
            'DN200': { c: '14187136', b: true },
            'DN300': { c: '9279667', b: true },
            'DN400': { c: '15060749', b: true },
            'DN500': { c: '9942354', b: true },
            'DN600': { c: '9793645', b: true },
            'DN800': { c: '14444970', b: true },
        },
    }
    dxfstruct.setShowLayers(newLayer)
    dxfstruct.resetDxf('user')

    console.log('dxfstruct', dxfstruct.dxf.entities.length)
    fs.writeFileSync(OUTPUT_FILE_NAME, JSON.stringify(dxfstruct.dxf));
    //console.log(dxfstruct.getDxfStruct())
});